﻿// -------------------------------------------------------------------------
//    @FileName         :    NFMMOOnlinePlayerPlugin.cpp
//    @Author           :    gaoyi
//    @Date             :    2025-02-27
//    @Email			:    445267987@qq.com
//    @Module           :    NFMMOOnlinePlayerPlugin
//
// -------------------------------------------------------------------------

#include "NFMMOOnlinePlayerPlugin.h"

#include <NFOnlineAcc.h>
#include <NFOnlineAccMgr.h>
#include <NFComm/NFObjCommon/NFTypeDefines.h>

#include "NFComm/NFPluginModule/NFIPluginManager.h"
#include "NFOnlinePlayerModule.h"
#include "NFOnlineRole.h"
#include "Trans/NFTransAccCreateRole.h"
#include "Trans/NFTransAccLogin.h"
#include "Trans/NFTransInsertAcc.h"
#include "Trans/NFTransInsertName.h"
#include "Trans/NFTransLoadAcc.h"
#include "Trans/NFTransSaveAcc.h"

#ifdef NF_DYNAMIC_PLUGIN

NF_EXPORT void DllStartPlugin(NFIPluginManager* pm)
{
    CREATE_PLUGIN(pm, NFMMOOnlinePlayerPlugin)

};

NF_EXPORT void DllStopPlugin(NFIPluginManager* pm)
{
    DESTROY_PLUGIN(pm, NFMMOOnlinePlayerPlugin)
};

#endif


//////////////////////////////////////////////////////////////////////////

int NFMMOOnlinePlayerPlugin::GetPluginVersion()
{
    return 0;
}

std::string NFMMOOnlinePlayerPlugin::GetPluginName()
{
    return GET_CLASS_NAME(NFMMOOnlinePlayerPlugin);
}

void NFMMOOnlinePlayerPlugin::Install()
{
    REGISTER_MODULE(m_pObjPluginManager, NFOnlinePlayerModule, NFOnlinePlayerModule);
}

void NFMMOOnlinePlayerPlugin::Uninstall()
{
    UNREGISTER_MODULE(m_pObjPluginManager, NFOnlinePlayerModule, NFOnlinePlayerModule);
}

bool NFMMOOnlinePlayerPlugin::InitShmObjectRegister()
{
    NFServerConfig* pConfig = FindModule<NFIConfigModule>()->GetAppConfig(NF_ST_ONLINE_SERVER);
    NF_ASSERT(pConfig);

    uint32_t maxOnlinePlayerNum = pConfig->GetMaxOnlinePlayerNum() * 1.2;

    REGISTER_SHM_OBJ(NFOnlineAcc, maxOnlinePlayerNum);
    REGISTER_SINGLETON_SHM_OBJ(NFOnlineAccMgr);

    REGISTER_SHM_OBJ(NFTransLoadAcc, maxOnlinePlayerNum/10);
    REGISTER_SHM_OBJ(NFTransInsertAcc, maxOnlinePlayerNum/10);
    REGISTER_SHM_OBJ(NFTransSaveAcc, maxOnlinePlayerNum/10);
    REGISTER_SHM_OBJ(NFTransInsertName, maxOnlinePlayerNum/10);

    REGISTER_SHM_OBJ(NFTransAccLogin, maxOnlinePlayerNum/10);
    REGISTER_SHM_OBJ(NFTransAccCreateRole, maxOnlinePlayerNum/10);

    REGISTER_SHM_OBJ_WITH_HASH(NFOnlineRole, maxOnlinePlayerNum);

    return true;
}